﻿Public Class FormTransform

    Public ColTextTransform As New ClassColTextTransform
 
    Private Sub ButtonAjout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAjout.Click
        Me.ContextMenuStrip1.Show(Me.ButtonAjout, New System.Drawing.Point(0, 0))
    End Sub

    Private Sub ListView1_MouseDoubleClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
        Dim oTrans As ClassTextOp = Me.ListView1.SelectedItems(0).Tag
        If oTrans.EditParams() Then Me.ListView1.SelectedItems(0).Text = oTrans.Caption
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If Me.ListView1.SelectedItems.Count > 0 Then
            Me.ButtonModif.Enabled = Me.ListView1.SelectedItems(0).Text.Contains("(")
        End If
    End Sub

    Private Sub ButtonModif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonModif.Click
        If Me.ListView1.SelectedItems.Count > 0 Then
            Dim oTrans As ClassTextOp = Me.ListView1.SelectedItems(0).Tag
            If oTrans.EditParams() Then Me.ListView1.SelectedItems(0).Text = oTrans.Caption
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Enregistrer une transformation
        Dim oTrans As ClassTextTransform
        If Me.ColTextTransform.Contains(Me.ComboBox1.Text) Then
            oTrans = Me.ColTextTransform(Me.ComboBox1.Text)
            oTrans.Titre = Me.ComboBox1.Text
            oTrans.GetFromForm()
        Else
            oTrans = New ClassTextTransform
            oTrans.Titre = Me.ComboBox1.Text
            oTrans.GetFromForm()
            Me.ColTextTransform.add(oTrans.Titre, oTrans)
            Me.ComboBox1.Items.Add(oTrans.Titre)
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If Me.ColTextTransform.Contains(Me.ComboBox1.Text) Then
            Me.ColTextTransform(Me.ComboBox1.Text).CopyToForm()
        End If
    End Sub

    Private Sub ButtonTester_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTester.Click
        Me.RichTextBoxResult.Text = Me.RichTextBox1.Text
        For Each oItem As ListViewItem In Me.ListView1.Items
            Dim OP As ClassTextOp = oItem.Tag
            Me.RichTextBoxResult.Text = OP.Transformer(Me.RichTextBoxResult.Text)
            My.Application.DoEvents()
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.ListView1.SelectedItems.Count > 0 Then
            Dim oItem As ListViewItem = Me.ListView1.SelectedItems(0)
            If oItem.Index > 0 Then
                Dim iIndex As Integer = oItem.Index - 1
                oItem.Remove()
                Me.ListView1.Items.Insert(iIndex, oItem)
                oItem.Selected = True
                oItem.EnsureVisible()
                Me.ListView1.Focus()
            End If
        End If
    End Sub

    Private Sub ButtonSupprime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSupprime.Click
        For Each oItem As ListViewItem In Me.ListView1.SelectedItems
            oItem.Remove()
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Me.ListView1.SelectedItems.Count > 0 Then
            Dim oItem As ListViewItem = Me.ListView1.SelectedItems(0)
            If oItem.Index < Me.ListView1.Items.Count - 1 Then
                Dim iIndex As Integer = oItem.Index + 1
                oItem.Remove()
                Me.ListView1.Items.Insert(iIndex, oItem)
                oItem.Selected = True
                oItem.EnsureVisible()
                Me.ListView1.Focus()
            End If
        End If
    End Sub

    Private Sub AjouterItem(ByRef oTrans As ClassTextOp)
        Dim oItem As ListViewItem
        If Me.ListView1.SelectedItems.Count > 0 Then
            oItem = Me.ListView1.Items.Insert(Me.ListView1.SelectedItems(0).Index, oTrans.Caption, oTrans.Operation.ToString)
        Else
            oItem = Me.ListView1.Items.Add(oTrans.Caption, oTrans.Operation.ToString)
        End If
        oItem.Tag = oTrans
    End Sub

    Private Sub TexteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TexteToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.RemplacerTexte
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub ExpressionRégulièreToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExpressionRégulièreToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.RemplacerRegEx
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub TableDeCaractèresToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TableDeCaractèresToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.RemplacerTableCar
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub MettreEnMajusculesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MettreEnMajusculesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Majuscules
        AjouterItem(oTrans)
    End Sub


    Private Sub MettreEnMinusculesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MettreEnMinusculesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Minuscules
        AjouterItem(oTrans)
    End Sub

    Private Sub JustifierToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JustifierToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Justifier
        AjouterItem(oTrans)
    End Sub

    Private Sub ReformaterEnLargeurToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReformaterEnLargeurToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.AjusterLargeur
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub SupprimerLesDoublesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerLesDoublesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.SupprimerDoubles
        AjouterItem(oTrans)
    End Sub


    Private Sub AligneEnColonnesSelonVirgulesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AligneEnColonnesSelonVirgulesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.MettreVirgulesEnColonnes
        AjouterItem(oTrans)
    End Sub

    Private Sub TrierLesColonnesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrierLesColonnesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.TrierEspaces
        AjouterItem(oTrans)
    End Sub

    Private Sub TrierSelonVirgulesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrierSelonVirgulesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.TrierVirgules
        AjouterItem(oTrans)
    End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Trier
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub AlignerLesPointsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignerLesPointsToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.AlignerPonctuation
        AjouterItem(oTrans)
    End Sub

    Private Sub AlignerLesVirgulesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignerLesVirgulesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.AlignerEgal
        AjouterItem(oTrans)
    End Sub

    Private Sub AlignerAutreToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignerAutreToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Aligner
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub ConvertirLignesEnListeAvecVirgulesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertirLignesEnListeAvecVirgulesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.LignesListe
        AjouterItem(oTrans)
    End Sub

    Private Sub ConvertirListeAvecVirgulesEnLignesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertirListeAvecVirgulesEnLignesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.ListeLignes
        AjouterItem(oTrans)
    End Sub

    Private Sub EncadrerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EncadrerToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Encadrer
        AjouterItem(oTrans)
    End Sub

    Private Sub CaractèresSpéciauxVersÉchapementUnicodeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaractèresSpéciauxVersÉchapementUnicodeToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.CarUnicode
        AjouterItem(oTrans)
    End Sub

    Private Sub ÉchapementUnicodeuxxxxVersCaractèreSpéciauxToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ÉchapementUnicodeuxxxxVersCaractèreSpéciauxToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.UnicodeCar
        AjouterItem(oTrans)
    End Sub

    Private Sub ToolStripMenuItem1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.MettreEspacesEnColonnes
        AjouterItem(oTrans)
    End Sub

    Private Sub MettreEnColonnesToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MettreEnColonnesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.MettreEnColonnes
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub TrierLesLignesToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrierLesLignesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.TrierLignes
        AjouterItem(oTrans)
    End Sub

    Private Sub SupprimerLesEspacesAvantToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerLesEspacesAvantToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.TrimAvant
        AjouterItem(oTrans)
    End Sub

    Private Sub SupprimerLesEspacesAprèsToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerLesEspacesAprèsToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.TrimApres
        AjouterItem(oTrans)
    End Sub

    Private Sub SupprimerLesEspacesEnAvantEtAprèstrimToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerLesEspacesEnAvantEtAprèstrimToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Trim
        AjouterItem(oTrans)
    End Sub

    Private Sub RetirerLesAccentsFrançaisToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetirerLesAccentsFrançaisToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.EnleverAccents
        AjouterItem(oTrans)
    End Sub

    Private Sub SupprimerLignesVidesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerLignesVidesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.SupprimerLignesVides
        AjouterItem(oTrans)
    End Sub

    Private Sub PivoterAutourDuSymboleToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PivoterAutourDuSymboleToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Pivoter
        AjouterItem(oTrans)
    End Sub

    Private Sub FusionnerLesLignesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FusionnerLesLignesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.FusionnerLignes
        AjouterItem(oTrans)
    End Sub

    Private Sub ScriptToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScriptToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.ScriptRemplacement
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub SéparerLesLignesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SéparerLesLignesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.SeparerLignes
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub PremièreLettreEnMajusculeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PremièreLettreEnMajusculeToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.PremiereLettre
        AjouterItem(oTrans)
    End Sub

    Private Sub FormTransform_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        If Me.ColTextTransform.Contains(Me.ComboBox1.Text) Then
            Me.ColTextTransform(Me.ComboBox1.Text).CopyToForm()
        End If
    End Sub

    Private Sub LookupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LookupToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Lookup
        oTrans.EditParams()
        If oTrans.Parametres(0) <> "" Then AjouterItem(oTrans)
    End Sub

    Private Sub NuméroterLesLignesSelonIndentationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NuméroterLesLignesSelonIndentationToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Numeroter
        AjouterItem(oTrans)
    End Sub

    Private Sub DénuméroterLesLignesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DénuméroterLesLignesToolStripMenuItem.Click
        Dim oTrans As New ClassTextOp()
        oTrans.Operation = ClassTextOp.EnumTextOperation.Denumeroter
        AjouterItem(oTrans)
    End Sub

    Private Sub ButtonOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOk.Click
        Dim oTrans As ClassTextTransform
        If Me.ColTextTransform.Contains(Me.ComboBox1.Text) Then
            oTrans = Me.ColTextTransform(Me.ComboBox1.Text)
            oTrans.Titre = Me.ComboBox1.Text
            oTrans.GetFromForm()
        Else
            oTrans = New ClassTextTransform
            oTrans.Titre = Me.ComboBox1.Text
            oTrans.GetFromForm()
            Me.ColTextTransform.add(oTrans.Titre, oTrans)
            Me.ComboBox1.Items.Add(oTrans.Titre)
        End If
    End Sub
End Class